package org.ccay.core.exception.impl;

import java.io.Serializable;

import org.ccay.core.log.CcayLoggerFactory;
import org.ccay.core.log.ILogger;
import org.ccay.core.request.IRequestContext;
import org.ccay.core.request.impl.RequestContext;

/**
 * 异常配置Bean，用于封装异常的本地化信息
 * 
 */
public class ExceptionConfigBean implements Serializable {
	
	private static final ILogger logger = CcayLoggerFactory.getLogger(ExceptionConfigBean.class);
	
	private static final long serialVersionUID = -7591425513455086762L;
	
	private static final String LANG_ZH_CN="zh_CN";
	
	private String enUS;
	
	private String zhCN;
	
	private String errorCode ;

	/**
	 * @return the errorCode
	 */
	public String getErrorCode() {
		return errorCode;
	}

	/**
	 * @param errorCode the errorCode to set
	 */
	public void setErrorCode(String errorCode) {
		this.errorCode = errorCode;
	}

	/**
	 * @return enUS
	 */
	public String getEnUS() {
		return enUS;
	}

	/**
	 * @param enUS 要设置的 enUS
	 */
	public void setEnUS(String enUS) {
		this.enUS = enUS;
	}

	/**
	 * @return zhCN
	 */
	public String getZhCN() {
		return zhCN;
	}

	/**
	 * @param zhCN 要设置的 zhCN
	 */
	public void setZhCN(String zhCN) {
		this.zhCN = zhCN;
	}

	/**
	 * 获取异常信息
	 * @return 本地化的异常信息
	 */
	public String getExceptionMessage() {
		try{
			IRequestContext  rc = RequestContext.getCurrent(true);
					
			if(rc != null && LANG_ZH_CN.equals(rc.getUserLanguage())){
				return getZhCN();
			}
			return getEnUS();
		}  catch(RuntimeException ex){
			logger.error(ex);
			//异常类不应该再往外抛异常
			return getEnUS();
		}
	}
	
	

}
